/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is Forte for Java, Community Edition. The Initial * Developer of the Original Code is Sun Microsystems, Inc. Portions * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved. */ package org.openide.src.nodes; import java.beans.Customizer; import java.beans.PropertyEditor; import java.util.ResourceBundle; import javax.swing.*; import javax.swing.border.*; import org.openide.src.*; import org.openide.explorer.propertysheet.*; import org.openide.explorer.propertysheet.editors.ModifierEditor; import org.openide.*; import org.openide.util.Utilities; import org.openide.util.NbBundle; import org.openide.util.HelpCtx; /** Customizer for FieldElement * * @author Petr Hamernik */ public class FieldCustomizer extends JPanel { /** Source of the localized human presentable strings. */ static ResourceBundle bundle = NbBundle.getBundle(FieldCustomizer.class); /** The edited field */ FieldElement element; /** Predefined types in the type combo */ private static final String[] COMMON_TYPES = { "String", // NOI18N "boolean", // NOI18N "char", // NOI18N "int", // NOI18N "long", // NOI18N "float", // NOI18N "double" // NOI18N }; /** Create new FieldCustomizer component * @param element The field to be customized */ public FieldCustomizer(FieldElement element) { this.element = element; initComponents (); //borders nameTypePanel.setBorder (new CompoundBorder( new TitledBorder(bundle.getString("CTL_FieldFrame")), new EmptyBorder(new java.awt.Insets(5, 5, 5, 5))) ); modifierPanel.setBorder (new TitledBorder(bundle.getString("CTL_Modifiers"))); initValuePanel.setBorder (new CompoundBorder( new TitledBorder(bundle.getString("CTL_InitValue")), new EmptyBorder(new java.awt.Insets(3, 3, 3, 3))) ); // modifiers PropertyPanel modifEditor = new PropertyPanel ( element, ElementProperties.PROP_MODIFIERS, PropertyPanel.PREF_CUSTOM_EDITOR ); modifierPanel.add(modifEditor); PropertyEditor propEdit = modifEditor.getPropertyEditor(); if (propEdit instanceof ModifierEditor) { ((ModifierEditor)propEdit).setMask(element.getModifiersMask()); } // name nameTextField.setText(element.getName().toString()); // type typeCombo.setSelectedItem(element.getType().toString()); // init value initValueEditor.setText(element.getInitValue()); HelpCtx.setHelpIDString (this, FieldCustomizer.class.getName ()); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the FormEditor. */ private void initComponents () {//GEN-BEGIN:initComponents nameTypePanel = new javax.swing.JPanel (); jLabel1 = new javax.swing.JLabel (); nameTextField = new javax.swing.JTextField (); jLabel2 = new javax.swing.JLabel (); typeCombo = new javax.swing.JComboBox(COMMON_TYPES); jPanel1 = new javax.swing.JPanel (); modifierPanel = new javax.swing.JPanel (); initValuePanel = new javax.swing.JPanel (); jScrollPane1 = new javax.swing.JScrollPane (); initValueEditor = new javax.swing.JEditorPane (); setLayout (new java.awt.GridBagLayout ()); java.awt.GridBagConstraints gridBagConstraints1; setBorder (new javax.swing.border.EmptyBorder(new java.awt.Insets(6, 6, 6, 6))); nameTypePanel.setLayout (new java.awt.GridBagLayout ()); java.awt.GridBagConstraints gridBagConstraints2; jLabel1.setText (bundle.getString("CTL_Name")); gridBagConstraints2 = new java.awt.GridBagConstraints (); gridBagConstraints2.insets = new java.awt.Insets (10, 0, 0, 8); gridBagConstraints2.anchor = java.awt.GridBagConstraints.EAST; nameTypePanel.add (jLabel1, gridBagConstraints2); nameTextField.addFocusListener (new java.awt.event.FocusAdapter () { public void focusLost (java.awt.event.FocusEvent evt) { nameTextFieldFocusLost (evt); } } ); gridBagConstraints2 = new java.awt.GridBagConstraints (); gridBagConstraints2.gridwidth = 0; gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints2.insets = new java.awt.Insets (10, 0, 0, 0); gridBagConstraints2.weightx = 1.0; nameTypePanel.add (nameTextField, gridBagConstraints2); jLabel2.setText (bundle.getString("CTL_Type")); gridBagConstraints2 = new java.awt.GridBagConstraints (); gridBagConstraints2.insets = new java.awt.Insets (8, 0, 0, 8); gridBagConstraints2.anchor = java.awt.GridBagConstraints.EAST; nameTypePanel.add (jLabel2, gridBagConstraints2); typeCombo.setEditable (true); typeCombo.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { jComboBox1ActionPerformed (evt); } } ); gridBagConstraints2 = new java.awt.GridBagConstraints (); gridBagConstraints2.gridwidth = 0; gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints2.insets = new java.awt.Insets (8, 0, 0, 0); gridBagConstraints2.weightx = 1.0; nameTypePanel.add (typeCombo, gridBagConstraints2); gridBagConstraints2 = new java.awt.GridBagConstraints (); gridBagConstraints2.weighty = 1.0; nameTypePanel.add (jPanel1, gridBagConstraints2); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.gridx = 0; gridBagConstraints1.gridy = 0; gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints1.weightx = 1.0; add (nameTypePanel, gridBagConstraints1); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.gridwidth = 0; gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH; add (modifierPanel, gridBagConstraints1); initValuePanel.setLayout (new java.awt.BorderLayout ()); initValueEditor.setPreferredSize (new java.awt.Dimension(321, 100)); initValueEditor.setContentType ("text/x-java"); // NOI18N initValueEditor.addFocusListener (new java.awt.event.FocusAdapter () { public void focusLost (java.awt.event.FocusEvent evt) { initValueEditorFocusLost (evt); } } ); jScrollPane1.setViewportView (initValueEditor); initValuePanel.add (jScrollPane1, java.awt.BorderLayout.CENTER); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.gridwidth = 2; gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints1.weightx = 1.0; gridBagConstraints1.weighty = 1.0; add (initValuePanel, gridBagConstraints1); }//GEN-END:initComponents private void jComboBox1ActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed String text = typeCombo.getSelectedItem().toString(); Type oldValue = element.getType(); boolean ok = false; try { Type newValue = Type.parse(text); if (!oldValue.equals(newValue)) { try { element.setType(newValue); ok = true; } catch (SourceException e) { TopManager.getDefault().notifyException(e); } } } catch (IllegalArgumentException e) { TopManager.getDefault().notify( new NotifyDescriptor.Message( bundle.getString("MSG_Not_Valid_Type"), NotifyDescriptor.ERROR_MESSAGE ) ); } if (!ok) typeCombo.setSelectedItem(oldValue.toString()); }//GEN-LAST:event_jComboBox1ActionPerformed private void initValueEditorFocusLost (java.awt.event.FocusEvent evt) {//GEN-FIRST:event_initValueEditorFocusLost if (evt.isTemporary()) return; String newText = initValueEditor.getText(); String oldText = element.getInitValue(); boolean ok = false; if (!newText.equals(oldText)) { try { element.setInitValue(newText); ok = true; } catch (SourceException e) { TopManager.getDefault().notifyException(e); } } if (!ok) initValueEditor.setText(oldText); }//GEN-LAST:event_initValueEditorFocusLost private void nameTextFieldFocusLost (java.awt.event.FocusEvent evt) {//GEN-FIRST:event_nameTextFieldFocusLost if (evt.isTemporary()) return; String newName = nameTextField.getText(); String oldName = element.getName().toString(); boolean ok = false; if (Utilities.isJavaIdentifier(newName)) { if (!oldName.equals(newName)) { Identifier id = Identifier.create(newName); try { element.setName(id); ok = true; } catch (SourceException e) { TopManager.getDefault().notifyException(e); } } } else { TopManager.getDefault().notify( new NotifyDescriptor.Message( bundle.getString("MSG_Not_Valid_Identifier"), NotifyDescriptor.ERROR_MESSAGE ) ); } if (!ok) nameTextField.setText(oldName); }//GEN-LAST:event_nameTextFieldFocusLost // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel nameTypePanel; private javax.swing.JLabel jLabel1; private javax.swing.JTextField nameTextField; private javax.swing.JLabel jLabel2; private javax.swing.JComboBox typeCombo; private javax.swing.JPanel jPanel1; private javax.swing.JPanel modifierPanel; private javax.swing.JPanel initValuePanel; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JEditorPane initValueEditor; // End of variables declaration//GEN-END:variables } /* * Log * 5 Gandalf 1.4 1/12/00 Petr Hamernik i18n using perl script * (//NOI18N comments added) * 4 Gandalf 1.3 1/11/00 Jesse Glick Context help. * 3 Gandalf 1.2 1/6/00 Petr Hamernik fixed 5040 * 2 Gandalf 1.1 12/9/99 Jan Jancura PropertyPanel changes * reflected. * 1 Gandalf 1.0 11/29/99 Petr Hamernik * $ */